﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.VisualStudio.TestTools.UITesting.WinControls;
using System.Diagnostics;
using Microsoft.VisualStudio.TestTools.UITesting;
using BackOffice.Context.UltiPro.BackOfficeUIMapClasses;
using System.Data.SqlClient;

namespace BackOffice.Context.UltiPro.Macros
{
    /// <summary>
    /// Database Macros
    /// </summary>
    public static class DatabaseMacros
    {
        public static void ExecuteSQL(string environment, string database, string sqlCommand)
        {
            using (SqlConnection conn = new SqlConnection(GetConnectionString(environment, database)))
            {
                conn.Open();
                using (SqlCommand cmd = new SqlCommand(sqlCommand, conn))
                {
                    try
                    {
                        cmd.ExecuteNonQuery();
                    }
                    catch (Exception ex)
                    {

                    }
                }
            }
        }

        private static string GetConnectionString(string environment, string database)
        {
            return String.Format(ConnectionString, Environment.SqlServer, database);
        }

        private static string ConnectionString
        {
            get
            {
                return Helpers.GetConfigValue("ConnectionString");
            }
        }
    }
}
